package com.laogao.controller;

import com.laogao.entity.Goods;
import com.laogao.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    // 根据 ID 查询商品
    //http://127.0.0.1:8080/goods/getById?goodsId=1
    @GetMapping("/getById")
    public Goods getById(@RequestParam("goodsId") String goodsId) {
        return goodsService.getGoodsIdById(goodsId);
    }

    // 更新商品信息
    @PostMapping("/update")
    public int update(@RequestBody Goods goods) {
        return goodsService.updateGoods(goods);
    }

    // 根据 ID 查询商品
    //http://127.0.0.1:8080/goods/getByIdV2?goodsId=1
    @GetMapping("/getByIdV2")
    public Goods getByIdV2(@RequestParam("goodsId") String goodsId) {
        return goodsService.getGoodsIdByIdV2(goodsId);
    }

    // 更新商品信息
    @PostMapping("/updateV2")
    public int updateV2(@RequestBody Goods goods) {
        return goodsService.updateGoodsV2(goods);
    }

}